<?php

namespace App\Http\Controllers\Campaign\Platform;

use App\Http\Controllers\BaseApiController;
use App\Services\Campaign\Platform\ExpertService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;

//专家讲堂控制器
class ExpertController extends  BaseApiController{

    private $service;
    private $result=[];

    //构造方法
    public function __construct(ExpertService $service)
    {
        //继承父类的构造方法
        parent::__construct();
        $this->service=$service;
    }

    //查询所有的  课程以及
    public function ExpertsAll(){
        //查询所有的
        $data=$this->service->SelAll();
        if($data==array()){
            return $this->fail(100);
        }else{
           return $this->success($data);
        }
    }



    //详情 专家视频详情
    public function ExpertsOne(Request $request){
        //接值  要查看的  专家id   判断非空
       $relus=[
           'id'=>'required|integer'
       ];
       //验错误
     if($error=$this->validate($relus,$request)){
         return $error;

     }
        //通过id  去查找  专家详情的内容
        $data=$this->service->SellOne($request);

        //判断返回值
        //查询失败
        if($data['code']!=200){
            return $this->fail($data);
        }
       else{
            //查询成功
            return $this->success($data);
        }

        }



        /**
         * 添加专家
         */
        public function ExpertAdd(Request $request){
            $relu=[
                'expertes_name'=>'required|string',
                'expertes_buscard'=>'required|string',
                'experts_title'=>'required|string',
                'experts_dgst'=>'required|string',
                'experts_type'=>'required|integer'
            ];
            $error=$this->validate($relu,$request);
            if($error){
                return $error;
            }
            $data=$this->service->ExpertsAdd($request);
        }


        public function FileAdd(){
            return view('ccc');
        }
        /**
         * 上传图片
         */
        public function ExpertImg(Request $request){
            $data=$this->service->UploadImgs($request);
            return $data;
        }





}
